/**
 * @param {string} s
 * @return {number}
 */
 var minSwaps = function(s) {
    let count = 0
    for(let ch of s){
        if(ch === '1')
            count++
    }
    if(Math.abs(2*count - s.length) > 1)
        return -1
    const len = s.length
    let t1 = '', t2 = ''
    for(let i = 0; i<len; i++){
        if(i%2 == 0){
            t1 += '0'
            t2 += '1'
        }
        else{
            t1 += '1'
            t2 += '0'
        }
    }
    let x = 0, y = 0
    for(let i = 0; i<s.length; i++){
        if(s[i] !== t1[i])
            x++
        if(s[i] !== t2[i])
            y++
    }
    if(len%2 === 0){
        return Math.min(x>>1, y>>1)
    }
    return 2*count > len ? y>>1 : x>>1
};